package com.ifinc.common.socket.model;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-30
 * Time: 18:06
 */
public class BaseResponse<T> {

    private T t;

    public static final BaseResponse NULL = new BaseResponse();

    protected Semaphore semaphore = new Semaphore(0);

    public void release() {
        semaphore.release(1);
    }

    public boolean waitForComplete() {
        TimeUnit unit = TimeUnit.MILLISECONDS;
        try {
            if (semaphore.tryAcquire(2000, unit)) {
                return Boolean.TRUE;
            } else {
                return Boolean.FALSE;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            return Boolean.FALSE;
        }
    }


    public void setResultResp(T t){
        this.t=t;
    }

    public T getResultResp() {
        return t;
    }
}
